
/* 购车人信息 */
function getGcr(url){
		$.dpAjax({
			show:false,
	 		url:url,
			data:{busiId:busiId},
			success: function(datas){
			  var data = datas.result;
			  if(data) {
				  //购车人信息
 				 var ywBusinessBuyers = data.ywBusinessBuyers;
 				 clearGcr();
 				 if(ywBusinessBuyers) {
     				 for(var key in ywBusinessBuyers) {
     					 var ywBusinessPartBuyers = ywBusinessBuyers[key];
     					 if(!ywBusinessPartBuyers || ywBusinessPartBuyers.length == 0) {
     						 continue;
     					 }
     					 var target = '';
	     				 if(key == '03') {
	     					target = 'zhujieren'; //购车人
	     					showBuer(target, ywBusinessPartBuyers[0]);
	     					showLi(target);
	     				 } else if(key == '01') {
	     					target = 'peiou';//共同购车人
	     					showBuer(target, ywBusinessPartBuyers[0]);
	     					showLi(target);
	     					$('.peiouqianzi').show();
	     				 } else if(key == '02') {
	     					target = 'danbaoren';//担保人
	     					showBuers(target, ywBusinessPartBuyers);
	     				 }
     				 }
 				 }
			  }
         }
 	});
}

//改变在职状态
	function changeJobStatus(target, jobStatus, affiliateStatus){
		if('01' == jobStatus) { //在职
			$('.' + target +'_job_status_rel_remark').hide();
	    	$('.' + target +'_job_status_rel').show();
	    	
			if(!affiliateStatus || affiliateStatus == '') {
				affiliateStatus = '01';
	 		}
			if('01' == affiliateStatus) { //不挂靠
		    	$('.' + target +'_affiliate_status_rel').hide();
	 		} else if('02' == affiliateStatus){ //挂靠
	 			$('.' + target +'_affiliate_status_rel').show();
	 		}
		} else if('02' == jobStatus){ //自由职业
			$('.' + target +'_job_status_rel').hide();
	    	$('.' + target +'_job_status_rel_remark').show();
	    	
			$('.' + target +'_affiliate_status_rel').hide();
		}
}


/**
 * @param target
 * @param type ''或History
 */
function showLi(target, type){
	type = type || '';
	$('#' +target+"Li" + type).show();
}

function hideLi(target, type){
	type = type || '';
	$('#' +target+"Li" + type).hide();
}

function showUl(target, type, currentTab){
	currentTabGlobal = currentTab;
	type = type || '';
	$('#' +target+"Ul" + type).show();
}

function hideTab(target, type){
	type = type || '';
	$('#' +target+"Li" + type).hide();
	$('#' +target+"Ul" + type).hide();
}

//所有购车人隐藏
function hideAllTabs(type){
	type = type || '';
	$('#zhujierenLi' + type).hide();
	$('#peiouLi' + type).hide();
	$('#danbaoren1Li' + type).hide();
	$('#danbaoren2Li' + type).hide();
	$('#danbaoren3Li' + type).hide();
	$('#danbaoren4Li' + type).hide();
	
	$('#zhujierenUl' + type).hide();
	$('#peiouUl' + type).hide();
	$('#danbaoren1Ul' + type).hide();
	$('#danbaoren2Ul' + type).hide();
	$('#danbaoren3Ul' + type).hide();
	$('#danbaoren4Ul' + type).hide();
	
	$('.peiouqianzi').hide();
}

//多个购车人
function showBuers(target, ywBusinessPartBuyers) {
	if(ywBusinessPartBuyers && ywBusinessPartBuyers.length > 0){
		for(var i = 0; i < ywBusinessPartBuyers.length; i++){
			var ywBusinessPartBuyer = ywBusinessPartBuyers[i];
			showBuer(target+(i+1),ywBusinessPartBuyer);
			showLi(target+(i+1));
		}
	}
}

//展示购车人
function showBuer(target, ywBusinessPartBuyer) {
	if(ywBusinessPartBuyer) {
		showBuerData(target, ywBusinessPartBuyer);
		if(target=='zhujieren' || target=='danbaoren1' || target=='danbaoren2' || target=='danbaoren3' || target=='danbaoren4') {
			$('#'+target+'_maritalStatus').text(ywBusinessPartBuyer.maritalStatusDisplay);
			$('#'+target+'_postcode').text(ywBusinessPartBuyer.postcode);
			$('#'+target+'_tel2').text(ywBusinessPartBuyer.tel2);
			$('#'+target+'_tel2Area').text(ywBusinessPartBuyer.tel2Area);
			$('#'+target+'_nowAddr').text(ywBusinessPartBuyer.nowAddr);
			$('#'+target+'_nowTel').text(ywBusinessPartBuyer.nowTel);
			$('#'+target+'_familyAddr').text(ywBusinessPartBuyer.familyAddr);
			$('#'+target+'_familyTel').text(ywBusinessPartBuyer.familyTel);
			$('#'+target+'_contact1').text(ywBusinessPartBuyer.contact1);
			$('#'+target+'_contact1Tel1').text(ywBusinessPartBuyer.contact1Tel1);
			$('#'+target+'_contact1Tel2').text(ywBusinessPartBuyer.contact1Tel2);
			$('#'+target+'_contact1Relation').text(ywBusinessPartBuyer.contact1RelationDisplay);
			$('#'+target+'_contact2').text(ywBusinessPartBuyer.contact2);
			$('#'+target+'_contact2Tel1').text(ywBusinessPartBuyer.contact2Tel1);
			$('#'+target+'_contact2Tel2').text(ywBusinessPartBuyer.contact2Tel2);
			$('#'+target+'_contact2Relation').text(ywBusinessPartBuyer.contact2RelationDisplay);
		} else if(target=='peiou') {
			$('#'+target+'_age').text(ywBusinessPartBuyer.age);
		}
		
		if(target=='zhujieren' && ywBusinessPartBuyer.remarkOpenCard != '') { //主借人开卡备注
			$('#'+target+'_remarkOpenCard').html(ywBusinessPartBuyer.remarkOpenCard);
		}
	}
}

function showBuerData(target, ywBusinessPartBuyer) {
	$('#'+target+'_id').text(ywBusinessPartBuyer.replaceId);
	$('#'+target+'_name').text(ywBusinessPartBuyer.name);
	$('#'+target+'_education').text(ywBusinessPartBuyer.educationDisplay);
	$('#'+target+'_familyRegister').text(ywBusinessPartBuyer.familyRegister);
	$('#'+target+'_sex').text(ywBusinessPartBuyer.sexDisplay);
	$('#'+target+'_idno').text(ywBusinessPartBuyer.idno);
	$('#'+target+'_area').text(ywBusinessPartBuyer.area);
	$('#'+target+'_tel1').text(ywBusinessPartBuyer.tel1);
	$('#'+target+'_tel1Area').text(ywBusinessPartBuyer.tel1Area);
	var jobStatus = ywBusinessPartBuyer.jobStatus;
	$('#'+target+'_jobStatus').text(ywBusinessPartBuyer.jobStatusDisplay);
	$('#'+target+'_affiliateStatus').text(ywBusinessPartBuyer.affiliateStatusDisplay);
	$('#'+target+'_company').text(ywBusinessPartBuyer.company);
	if('01' == jobStatus) {
		$('#'+target+'_companyIncome').text(ywBusinessPartBuyer.companyIncome);
	} else if('02' == jobStatus){
		$('#'+target+'_companyIncome_remarks').text(ywBusinessPartBuyer.companyIncome);
	}
	$('#'+target+'_companyAddr').text(ywBusinessPartBuyer.companyAddr);
	$('#'+target+'_job').text(ywBusinessPartBuyer.jobDisplay);
	$('#'+target+'_monthIncome').text(ywBusinessPartBuyer.monthIncome);
	$('#'+target+'_workAge').text(ywBusinessPartBuyer.workAgeDisplay);
	$('#'+target+'_companyTel').text(ywBusinessPartBuyer.companyTel);
	$('#'+target+'_remarks').html(ywBusinessPartBuyer.remarks);
	changeJobStatus(target, jobStatus,ywBusinessPartBuyer.affiliateStatus);
	
	$('zhujieren_idno').text(ywBusinessPartBuyer.idno);
	changeIdNo();
}

function changeIdNo(){
	var UUserCard = $("#zhujieren_idno").text(); 
	if(UUserCard && UUserCard !=""){
		if(UUserCard != null && UUserCard != ''){
		//获取年龄 
		var myDate = new Date(); 
		var month = myDate.getMonth() + 1; 
		var day = myDate.getDate();
		var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1; 
		if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) { 
			age++; 
		}
			$("#zhujieren_age").text(age);
		}
		else{
			$("#zhujieren_age").text("-");
		}
	}	
}


function clearGcr(){
	var zhujieren = $('#zhujieren_idno');
	if(zhujieren) {
		clearBuerData('zhujieren');
		clearZhujierenData('zhujieren');
		$('#zhujieren_remarkOpenCard').html('-');
	}
	
	var peiou = $('#peiou_idno');
	if(peiou) {
		clearBuerData('peiou');
		$('#peiou_age').text('-');
	}
	
	var danbaoren1 = $('#danbaoren1_idno');
	if(danbaoren1) {
		clearBuerData('danbaoren1');
		clearZhujierenData('danbaoren1');
	}
	var danbaoren2 = $('#danbaoren2_idno');
	if(danbaoren2) {
		clearBuerData('danbaoren2');
		clearZhujierenData('danbaoren2');
	}
	var danbaoren3 = $('#danbaoren3_idno');
	if(danbaoren3) {
		clearBuerData('danbaoren3');
		clearZhujierenData('danbaoren3');
	}
	var danbaoren4 = $('#danbaoren4_idno');
	if(danbaoren4) {
		clearBuerData('danbaoren4');
		clearZhujierenData('danbaoren4');
	}
}

function clearZhujierenData(target){
	$('#'+target+'_maritalStatus').text('-');
	$('#'+target+'_postcode').text('-');
	$('#'+target+'_tel2').text('-');
	$('#'+target+'_tel2Area').text('-');
	$('#'+target+'_nowAddr').text('-');
	$('#'+target+'_nowTel').text('-');
	$('#'+target+'_familyAddr').text('-');
	$('#'+target+'_familyTel').text('-');
	$('#'+target+'_contact1').text('-');
	$('#'+target+'_contact1Tel1').text('-');
	$('#'+target+'_contact1Tel2').text('-');
	$('#'+target+'_contact1Relation').text('-');
	$('#'+target+'_contact2').text('-');
	$('#'+target+'_contact2Tel1').text('-');
	$('#'+target+'_contact2Tel2').text('-');
	$('#'+target+'_contact2Relation').text('-');
}

function clearBuerData(target) {
	$('#'+target+'_id').text('-');
	$('#'+target+'_name').text('-');
	$('#'+target+'_education').text('-');
	$('#'+target+'_familyRegister').text('-');
	$('#'+target+'_sex').text('-');
	$('#'+target+'_idno').text('-');
	$('#'+target+'_area').text('-');
	$('#'+target+'_tel1').text('-');
	$('#'+target+'_tel1Area').text('-');
	$('#'+target+'_company').text('-');
	$('#'+target+'_companyAddr').text('-');
	$('#'+target+'_job').text('-');
	$('#'+target+'_monthIncome').text('-');
	$('#'+target+'_workAge').text('-');
	$('#'+target+'_companyTel').text('-');
	$('#'+target+'_remarks').html('-');
}